/*处于复数运算层，使用底层的抽象接口就行了*/
#include <math.h>
#include<stdio.h>

struct complex_struct {
	double x, y;
};

double real_part(struct complex_struct z)
{
	return z.x;
}

double img_part(struct complex_struct z)
{
	return z.y;
}

double magnitude(struct complex_struct z)
{
	return sqrt(z.x * z.x + z.y * z.y);
}

double angle(struct complex_struct z)
{
	return atan2(z.y, z.x);
}

void print_complex(struct complex_struct z)
{
    if (real_part(z))
    {
        printf("%f", real_part(z));
        if (img_part(z))
            printf("+");
    }
    
    if (img_part(z))
        printf("%fi", img_part(z));

    if (!real_part(z) && !img_part(z))
        printf("0");
    printf("\n");
}

int main()
{
    struct complex_struct z = {1.0, 0};
    print_complex(z);

    return 0;
}
